package com.hua.yuan.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.hua.yuan.common.BaseActivity;
import com.hua.yuan.R;
import com.hua.yuan.ui.adapter.MyBuyAdapter;
import com.hua.yuan.ui.module.MyBuyBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huangyang on 2018/6/23.
 * 购买记录的activity
 */

public class MyBuyActivity extends BaseActivity implements View.OnClickListener {

    private ImageView backImage;
    private TextView titleView;
    private ListView listView;

    private MyBuyAdapter adapter;

    private String testImage = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1530353595&di=e3c6526c6acf0ad09d04500def50d101&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.jznews.com.cn%2Fpic%2F0%2F12%2F84%2F95%2F12849580_461505.jpg";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_my_buy);

        initView();
        initData();

    }

    private void initView() {

        backImage = findViewById(R.id.backImage);
        titleView = findViewById(R.id.titleView);
        listView = findViewById(R.id.listView);
        adapter = new MyBuyAdapter(this);


    }

    private void initData() {

        backImage.setOnClickListener(this);
        titleView.setText("我的购买");
        listView.setAdapter(adapter);

        createData();

    }

    private void createData() {

        List<MyBuyBean> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            MyBuyBean bean = new MyBuyBean();
            bean.setImageUrl(testImage);
            bean.setName("名字" + i);
            bean.setType("类型" + i);
            bean.setPlayTime("播放时间" + i);
            bean.setMoney((100 + i) + "代币");
            bean.setBuyTime("购买时间" + i);
            list.add(bean);
        }

        adapter.setList(list);
        adapter.notifyDataSetChanged();

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.backImage:
                finish();
                break;
        }
    }


}
